home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / getarg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  2.3 KB  |  77 lines

  1. /*
  2. \fucref{getarg}{char $*$getarg (\params)}
  3.     {
  4.         {int} {n} {{\em n}-th argument to retrieve}
  5.         {int} {*increment} {address of counter increment}
  6.     }
  7.     {argument in string format}
  8.     {xstrdup()}
  9.     {}
  10.     {getarg.c}
  11.     {
  12.  
  13.         Function {\em getarg()} can be called to retrieve arguments from the
  14.         stack (e.g., the arguments of a {\em print()} statement) in string
  15.         format. Parameter {\em n} specifies the argument to retrieve: 0 is the
  16.         last pushed argument, 1 is the argument pushed before that, etc..
  17.  
  18.         Parameter {\em increment} tells the caller whether to start retrieving
  19.         a next argument or not. In the case of a list argument, {\em getarg()}
  20.         sets this flag to 0 while the list is not yet completely processed.
  21.  
  22.         When a list argument is processed or when the retrieved argument is not
  23.         a list, the flag value is set to 1.
  24.  
  25.         The return value points to a string duplicate. The caller should free
  26.         this memory when it is no longer needed.
  27.  
  28.     }
  29. */
  30.  
  31. #include "icm-exec.h"
  32.  
  33. char *getarg (n, flag)
  34. int n;
  35. int *flag;
  36. {
  37.     char
  38.         convbuf [50];
  39.     static unsigned
  40.         listindex;
  41.     register char
  42.         *ret;
  43.  
  44.     *flag = 1;                              /* assume that done with args */
  45.  
  46.     if (stack [sp - n].type & e_int)        /* incase of an int.. */
  47.     {
  48.         listindex = 0;
  49.         sprintf (convbuf, "%d", stack [sp - n].vu.intval);
  50.         return (xstrdup (convbuf));
  51.     }
  52.  
  53.     if (stack [sp - n].type & e_str)        /* incase of a string.. */
  54.     {
  55.         listindex = 0;
  56.         return (xstrdup (stack [sp - n].vu.i->ls.str));
  57.     }
  58.  
  59.                                             /* incase of a list: */
  60.     if (! stack [sp - n].vu.i->ls.list.size)
  61.     {
  62.         listindex = 0;
  63.         ret = xstrdup (nullstring);
  64.     }
  65.     else
  66.     {
  67.         ret = xstrdup (stack [sp - n].vu.i->ls.list.element [listindex]);
  68.         listindex++;
  69.         if (listindex < stack [sp - n].vu.i->ls.list.size)
  70.             *flag = 0;                      /* if more elements, not done */
  71.         else                                /* with args.. */
  72.             listindex = 0;                  /* otherwise: returnflag = 1, */
  73.     }                                       /* no next elements to get */
  74.  
  75.     return (ret);
  76. }
  77.